define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
            Table.api.init({
                extend: {
                    index_url: 'socialized/index' + location.search,
                    edit_url: 'socialized/edit',
                    del_url: '',
                    table: 'socialized',
                },
            });
            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: '', title: __('序号'),operate:false,table: table,width:'30px',formatter:Table.api.formatter.natureorder},
                        {field: 'name', title: __('Name'),
                            formatter:function(value,row,index){
                              //此处对value值做判断，不然value为空就会报错
                              if(row.name && row.name.length<=12){
                                return row.name;
                              }
                              if(row.name && row.name.length>12){
                                return row.name.substring(0,11)+"...";
                              }
                            }
                        },
                        {field: 'referrer', title: __('引荐人')},
                        {field: 'investment_name', title: __('投资方')},
                        // {field: 'planned_street', title: __('拟落户街道')},
                        {field: 'settle_street', title: __('落户街道'),
                            formatter: function(value, row, index) {
                                if(row.library_id == 1)
                                    return row.planned_street_names;
                                if(row.library_id == 2)
                                    return row.settle_street_names;
                            }
                        },
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            })
            Table.api.bindevent(table);
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    }
    return Controller;
})